<?php

namespace app\common\model;


class RechargeModel extends BaseModel
{
    public static function pay_notify($param)
    {
        if (!is_array($param) || count($param) == 0) {
            return self::setErrorInfo('回调参数异常:' . json_encode($param));
        }

        $order_no = $param['out_trade_no'];
        $trade_no = $param['trade_no'];
        $info = self::where('order_no', $order_no)->find();
        if ($info->status == 1) {
            return true;
        }
        self::beginTrans();
        $rs1 = $info->save(['status' => 1, 'trade_no' => $trade_no, 'uptime' => time()]);
        if (!$rs1) {
            self::rollbackTrans();
            return self::setErrorInfo('订单更新失败');
        }
        $rs2 = MoneyLogModel::addLog($info['user_id'], $info['money'], 2, '线上充值', $info['order_no']);
        if (!$rs2) {
            self::rollbackTrans();
            return self::setErrorInfo(self::getErrorInfo());
        }
        self::commitTrans();
        return true;

    }
}
